package edu.ua.jCompare;

import java.util.List;

public class HTMLRenderer implements Renderer {

	public enum Tag {
		 DELETE("del"), INSERT("ins"), MATCH("");
		 
		 private String name;
		 
		 private Tag(String n) {
		   name = n;
		 }
		 
		 public String getName() {
			 return name;
		 }
	}
	
	public enum Color {
		 GREEN("green"), RED("red"), BLACK("black");
		 
		 private String name;
		 
		 private Color(String n) {
		   name = n;
		 }
		 
		 public String getName() {
			 return name;
		 }
	}
		   
	
	
	private String matchTag = "";
	private String insertTag = "ins";
	private String deleteTag = "del";
	
	private String delColor = "red";
	private String insColor = "green";
	
	private String htmlOut = "";
	
	@Override
	public void renderDeletes(List<String> items){
		htmlOut += render(items, Tag.DELETE, Color.RED);
	}
	
	@Override
	public void renderInserts(List<String> items){
		htmlOut += render(items, Tag.INSERT, Color.GREEN);
	}
	
	@Override
	public void renderMatches(List<String> items){
	    htmlOut += render(items, Tag.MATCH, Color.BLACK);
	}
	
	private String render(List<String> items, Tag tag, Color color){
		String out = "";
		if (!tag.name.equals(""))
			out += "<font color=\"" + color.name +"\"><" + tag.name + ">";
		for (String item:items){
			out += item + " ";
		}
		if (!tag.name.equals(""))
			out += "</" + tag + "></font>";
		return out;
	}
	
	@Override
	public void finalize(){
		System.out.println(htmlOut);
	}
	
	public void initialize(){
		return;
	}
	

}
